package com.ruoyi.system.service.customer.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.system.domain.customer.CustomerLogin;
import com.ruoyi.system.domain.customer.ZeroYuanService;
import com.ruoyi.system.mapper.customer.ZeroYuanServiceMapper;
import com.ruoyi.system.service.customer.ZeroYuanServiceService;
import com.ruoyi.system.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class ZeroYuanServiceServiceImpl implements ZeroYuanServiceService {

    @Autowired
    private ZeroYuanServiceMapper zeroYuanServiceMapper;

    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private HttpServletRequest request;

    @Override
    public String checkcustomerIdUnique(ZeroYuanService zeroYuanService) {
        CustomerLogin customerLogin = tokenUtils.getLoginCustomer(request);
        zeroYuanService.setCustomerId(customerLogin.getCustomerId());

        int count = zeroYuanServiceMapper.checkcustomerIdUnique(zeroYuanService);
        System.err.println("******************ccount***************"+count);
        if(count > 0){
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 查询零元质检
     *
     * @param zeroId 零元质检ID
     * @return 零元质检
     */
    @Override
    public ZeroYuanService selectZeroYuanServiceById(Integer zeroId)
    {
        return zeroYuanServiceMapper.selectZeroYuanServiceById(zeroId);
    }

    @Override
    public ZeroYuanService customerIdServiceById(Long customerId) {
        return zeroYuanServiceMapper.customerIdServiceById(customerId);
    }

    /**
     * 查询零元质检列表
     *
     * @param zeroYuanService 零元质检
     * @return 零元质检
     */
    @Override
    public List<ZeroYuanService> selectZeroYuanServiceList(ZeroYuanService zeroYuanService)
    {
        return zeroYuanServiceMapper.selectZeroYuanServiceList(zeroYuanService);
    }

    /**
     * 新增零元质检
     *
     * @param zeroYuanService 零元质检
     * @return 结果
     */
    @Override
    public int insertZeroYuanService(ZeroYuanService zeroYuanService)
    {
        return zeroYuanServiceMapper.insertZeroYuanService(zeroYuanService);
    }

    /**
     * 修改零元质检
     *
     * @param zeroYuanService 零元质检
     * @return 结果
     */
    @Override
    public int updateZeroYuanService(ZeroYuanService zeroYuanService)
    {
        return zeroYuanServiceMapper.updateZeroYuanService(zeroYuanService);
    }

    @Override
    public int updateZeroYuan(ZeroYuanService zeroYuanService) {
        return zeroYuanServiceMapper.updateZeroYuan(zeroYuanService);
    }

    /**
     * 批量删除零元质检
     *
     * @param zeroIds 需要删除的零元质检ID
     * @return 结果
     */
    @Override
    public int deleteZeroYuanServiceByIds(Long[] zeroIds)
    {
        return zeroYuanServiceMapper.deleteZeroYuanServiceByIds(zeroIds);
    }

    /**
     * 删除零元质检信息
     *
     * @param zeroId 零元质检ID
     * @return 结果
     */
    @Override
    public int deleteZeroYuanServiceById(Integer zeroId)
    {
        return zeroYuanServiceMapper.deleteZeroYuanServiceById(zeroId);
    }

}
